package yanyan.com.tochar.utils;

import java.util.ArrayList;
import java.util.List;

public class StringUtil {


    /**
     * 取中间文本
     * @param all
     * @param leftStr
     * @param rightStr
     * @return
     */
    public  static String getMiddleStr(String all,String leftStr,String rightStr){
        int start=0;
        int end=all.length();
        int i = all.indexOf(leftStr);
        if(i>=0){
            start=i+leftStr.length();
        }
        int y = all.indexOf(rightStr, start);
        if(y>0){
            end=y;
        }
        if(rightStr.length()==0 || rightStr==""){
            end=all.length();
        }
        return all.substring(start,end);
    }

    /**
     * 取文本集合
     * @param all
     * @param leftStr
     * @param rightStr
     * @return
     */
    public static List<String> getMiddleStrList(String all,String leftStr,String rightStr){
        List<String> res=new ArrayList<>();
        while (true){
            int start = all.indexOf(leftStr);
            int end = all.substring(all.indexOf(leftStr) + leftStr.length()).indexOf(rightStr);
            if(start<=-1 || end<=-1){
                break;
            }
            String s=getMiddleStr(all,leftStr,rightStr);
            res.add(s);
            all=all.substring(all.indexOf(rightStr,all.indexOf(leftStr))+rightStr.length());
        }
        return res;
    }

    public static void main(String [] s){

        String str="<!DOCTYPE html>\n" +
                "<html>\n" +
                "<head>\n" +
                "    <meta charset=\"utf-8\">\n" +
                "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n" +
                "    <meta name=\"apple-mobile-web-app-capable\" content=\"yes\" />\n" +
                "    <meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black\" />\n" +
                "    <meta name=\"format-detection\" content=\"telphone=no, email=no\" />\n" +
                "    <meta name=\"theme-color\" content=\"#ff6600\" />\n" +
                "    <!-- Windows Phone -->\n" +
                "    <meta name=\"msapplication-navbutton-color\" content=\"#4285f4\">\n" +
                "    <!-- iOS Safari -->\n" +
                "    <meta name=\"apple-mobile-web-app-capable\" content=\"yes\">\n" +
                "    <meta name=\"apple-mobile-web-app-status-bar-style\" content=\"black-translucent\">\n" +
                "    <title>www.baidu.com网站备案查询 - 站长工具</title>\n" +
                "    <meta name=\"keywords\" content=\"网站备案查询\" />\n" +
                "    <meta name=\"description\" content=\"站长工具提供网站备案信息查询，通过域名可查询该域名www.baidu.com是否有备案及相关的备案信息。\" />\n" +
                "    <link rel=\"stylesheet\" href=\"//csstools.chinaz.com/common/boot3.3.7/css/bootstrap.min.css\" />\n" +
                "    <link rel=\"stylesheet\" href=\"//csstools.chinaz.com/common/wap/iconfont/iconfont.css\" />\n" +
                "    <link rel=\"stylesheet\" href=\"//csstools.chinaz.com/common/wap/normalize.css\" />\n" +
                "    <link rel=\"stylesheet\" href=\"//csstools.chinaz.com/common/wap/t-common.css?v=20180717\" />\n" +
                "    <link rel=\"stylesheet\" href=\"//csstools.chinaz.com/tools/wap/css/t-icpstyle.css?v=20180717\" />\n" +
                "    <script>\n" +
                "        var subNavIndex = '0';\n" +
                "    </script>\n" +
                "    <script src=\"//csstools.chinaz.com/common/js/jquery.min.js\"></script>\n" +
                "    <script src=\"//csstools.chinaz.com/common/boot3.3.7/js/bootstrap.min.js\"></script>\n" +
                "    <script src=\"//csstools.chinaz.com/common/wap/t-common.js?v=20180606\"></script>\n" +
                "    <script src=\"//csstools.chinaz.com/tools/wap/function/global.js?v=20180529\"></script>\n" +
                "        <script src=\"//csstools.chinaz.com/tools/wap/function/prototype.js?v=20180529\"></script>\n" +
                "</head>\n" +
                "<body>\n" +
                "    <!--页面头部-->\n" +
                "    <nav class=\"tw-navbar\" id=\"top\">\n" +
                "        <div class=\"tw-navcont\">\n" +
                "            <div class=\"tw-navtxt clearfix\">\n" +
                "                <a href=\"//mtool.chinaz.com/\" class=\"btn pull-left tw-nav-l\"><span class=\"iconfont icon-home\"></span></a>\n" +
                "                <div class=\"tw-navtitle\">网站备案</div>\n" +
                "                <a href=\"javascript:\" class=\"btn pull-right tw-nav-r js-menu\"><span class=\"iconfont icon-list1\"></span></a>\n" +
                "            </div>\n" +
                "        </div>\n" +
                "    </nav>\n" +
                "    <!--导航栏-->\n" +
                "    <div class=\"navbarwarp\">\n" +
                "        <div id=\"tw-subnavbar\">\n" +
                "            <ul class=\"swiper-wrapper\">\n" +
                "                <li class=\"swiper-slide on\"><a href=\"/?query=www.baidu.com\" rel=\"/\">网站备案</a></li>\n" +
                "                <li class=\"swiper-slide\"><a href=\"/Icp/Psorgan/?query=www.baidu.com\" rel=\"/Icp/Psorgan/\">网安备案</a></li>\n" +
                "                <li class=\"swiper-slide\"><a href=\"/Icp/Report/\" rel=\"/Icp/Report/\">接入商</a></li>\n" +
                "                <li class=\"swiper-slide\"><a href=\"/Icp/BatchSearchs/\" rel=\"/Icp/BatchSearchs/\">备案批量查询</a></li>\n" +
                "            </ul>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "    <!--页面内容-->\n" +
                "    \n" +
                "\n" +
                "<!--搜索栏-->\n" +
                "<div class=\"discover bgcligdis\">\n" +
                "    <form method=\"post\" id=\"icp-form\">\n" +
                "        <div class=\"input-group\">\n" +
                "            <div class=\"input-group-btn dropsch-group\" id=\"dropsch\">\n" +
                "                <button type=\"button\" class=\"btn dropsch\" data-toggle=\"dropdown\">网站域名<span class=\"caret\"></span></button>\n" +
                "                <ul class=\"dropdown-menu dropsch-menu\">\n" +
                "                    <li><a href=\"javascript:\" data-value=\"host\">网站域名</a></li>\n" +
                "                    <li><a href=\"javascript:\" data-value=\"num\">备案号</a></li>\n" +
                "                </ul>\n" +
                "            </div>\n" +
                "            <a href=\"javascript:\" class=\"dis-clear\"><span class=\"iconfont icon-wrong\">&nbsp;</span></a>\n" +
                "            <input type=\"text\" class=\"form-control tw-input-list\" placeholder=\"请输入域名\" data-toggle=\"collapse\" data-type=\"inputbox_urls\" value=\"www.baidu.com\" id=\"query\" name=\"query\">\n" +
                "            <div class=\"input-txtlist collapse\" id=\"suffix-floor\">\n" +
                "                <ul class=\"list-group dorecord-list\"></ul>\n" +
                "                <div class=\"mb10 clearhis\"><button type=\"button\" class=\"btn btn-primary btn-xs z-fl\" data-type=\"inputbox_urls\">清除记录</button> <a href=\"javascript:\" class=\"chis-close\">关闭</a> </div>\n" +
                "            </div>\n" +
                "            <span class=\"input-group-btn\"><button class=\"btn dis-btn\" type=\"submit\">查询</button></span>\n" +
                "        </div>\n" +
                "        <div class=\"perk-btn z-tl mb0\"><input type=\"checkbox\" id=\"asslk\" class=\"\" name=\"asslk\"><label for=\"asslk\">更新缓存</label></div>\n" +
                "        <div class=\"perk-open z-pt2\">\n" +
                "            <input type=\"text\" class=\"form-control angle VeriTxt z-fl\" placeholder=\"验证码\" id=\"checkcode\" name=\"checkcode\">\n" +
                "            <div class=\"z-fl Vericode z-ml3\" id=\"imgcode\"></div>\n" +
                "            <p class=\"z-clear z-pt2 z-tl c-39\">输入验证码可查询最新的数据，不填则是缓存数据。</p>\n" +
                "        </div>\n" +
                "        <input id=\"accessmode\" name=\"accessmode\" type=\"hidden\" value=\"host\" />\n" +
                "        <input id=\"isshowcode\" name=\"isshowcode\" type=\"hidden\" value=\"0\" />\n" +
                "        <input id=\"guid\" name=\"guid\" type=\"hidden\" value=\"102df90c-0bcc-404a-97cd-475fd408ff6f\" />\n" +
                "    </form>\n" +
                "    <div class=\"z-tl mb0\">\n" +
                "        <span id=\"errorinfo\" class=\"c-red\">提示：被屏蔽的域名</span>\n" +
                "    </div>\n" +
                "    <script src=\"//csstools.chinaz.com/tools/wap/function/icp.js?v=20180717\"></script>\n" +
                "    <script>\n" +
                "        var assbtn = $(\".perk-btn>input\");\n" +
                "        var isshowcode = $(\"#isshowcode\").val(); //'0';\n" +
                "        if(isshowcode)\n" +
                "        {\n" +
                "            if(isshowcode == \"1\")\n" +
                "            {\n" +
                "                assbtn.addClass(\"on\");\n" +
                "                $(\".perk-open\").show();\n" +
                "                $(\"#checkcode\").focus();\n" +
                "                assbtn.attr(\"checked\",\"checked\");\n" +
                "                GetImg(0);\n" +
                "            }\n" +
                "        }\n" +
                "        //更新缓存\n" +
                "        assbtn.click(function () {\n" +
                "            GetImg(0);\n" +
                "        });\n" +
                "    </script>\n" +
                "</div>\n" +
                "<!--左侧浮动导航栏-->\n" +
                "<div class='bg-nav'><div class='closebg'><a href='javascript:'><span class='iconfont icon-close1'></span></a></div></div>\n" +
                "<div class='SideNavbar'>\n" +
                "    <div class='nb-list'><a href='//mtool.chinaz.com/' class='nb-listhd'>工具首页</a></div>\n" +
                "    <div class='nb-list'><a href='//mseo.chinaz.com/' class='nb-listhd'>SEO综合查询</a></div>\n" +
                "    <div class='nb-list'><a href='//mrank.chinaz.com/all/' class='nb-listhd'>综合权重查询</a></div>\n" +
                "    <div class='nb-list'><a href='//mindex.chinaz.com/' class='nb-listhd'>指数查询</a></div>\n" +
                "    <div class='nb-list'><a href='//mtool.chinaz.com/othertools' class='nb-listhd'>更多工具</a></div>\n" +
                "</div>\n" +
                "\n" +
                "<div class=\"bg10\"></div>\n" +
                "<div class=\"z-loding\" style=\"display:none\">\n" +
                "    <h4><img src=\"//csstools.chinaz.com/tools/images/public/spinner.gif\">&nbsp; 正在请求数据,请稍候...</h4>\n" +
                "</div>\n" +
                "<!--页面内容-->\n" +
                "    <div class=\"contnull\">\n" +
                "        <i class=\"iconfont icon-news01 null-c\"></i>\n" +
                "        <h4>未查询任何数据</h4>\n" +
                "    </div>\n" +
                "\n" +
                "    <!--ad-->\n" +
                "    <div class=\"bg10\"></div>\n" +
                "    <script src=\"//stats.chinaz.com/mt_g/wap_mhome.js\" type=\"text/javascript\"></script>\n" +
                "    <!--工具简介-->\n" +
                "    <div class=\"bg10\"></div>\n" +
                "    <div class=\"tool-intro lh24\">\n" +
                "        <div class=\"mb10\"><span class=\"c-blue\">工具简介</span></div>\n" +
                "        <p>网站ICP备案查询，查看网站是否已经备案及备案情况。</p>\n" +
                "    </div>\n" +
                "    <!--页面底部-->\n" +
                "    <div class=\"navbar navbar-default\" id=\"tw-ftwrap\">\n" +
                "        <div class=\"clearfix\">\n" +
                "            <a href=\"/\" class=\"gbrand\"><img src=\"//csstools.chinaz.com/tools/wap/img/mlogo/micp.gif\"></a>\n" +
                "            <div class=\"tw-ftlink\"><a href=\"http://icp.chinaz.com\">电脑端</a><span>丨</span><a href=\"javascript:\" id=\"fotTopId\">回顶部</a></div>\n" +
                "        </div>\n" +
                "    </div>\n" +
                "    <div class=\"floatwrap\" id=\"wTopId\">\n" +
                "        <a href=\"javascript:\" class=\"floatop\" id=\"goTopBtn\" title=\"返回顶部\"><span class=\"iconfont icon-top1 fz24\"></span></a>\n" +
                "    </div>\n" +
                "    <!--统计-->\n" +
                "    <div style=\"display: none\">\n" +
                "        <script src='//s11.cnzz.com/stat.php?id=5082706&web_id=5082706' charset='gb2312'></script>\n" +
                "    </div>\n" +
                "    <a href=\"//mtool.chinaz.com/othertools/\" style=\"display:none\"></a>\n" +
                "    <script>\n" +
                "        $(\".z-loding\").hide();\n" +
                "    </script>\n" +
                "</body>\n" +
                "</html>";
        String  ss=StringUtil.getMiddleStr(str,"<table class=\"table mb0\">","</tbody>");
        System.out.println(ss);
    }
}
